<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 10475
  Date: 2023/2/21
  Time: 15:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>招聘用户列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/layui-v2.6.3/css/layui.css" media="all">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>
<fieldset class="table-search-fieldset">
    <legend>搜索信息</legend>
    <div style="margin: 10px 10px 10px 10px" class="demoTable">
        <div class="layui-form" lay-filter="useradmin" id="useradmin">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">职位号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="jobId"  id="jobId" autocomplete="off" class="layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">开始时间:</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" id="keyCreateTime" name="keyCreateTime" lay-verify="required"  autocomplete="off"  placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束时间:</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" id="keyEndTime" name="keyEndTime" lay-verify="required"  autocomplete="off"  placeholder="yyyy-MM-dd">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">审核状态</label>
                    <div class="layui-input-inline">
                        <select id="keyState" class="layui-border" lay-ignore>
                            <option value="">请选择</option>
                            <option value="未审批">未审批</option>
                            <option value="同意">同意</option>
                            <option value="拒绝">拒绝</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button  type="button" class="layui-btn" data-type="reload" onclick="select()" id="find"><i class="layui-icon"></i> 搜 索</button>
                </div>
            </div>
        </div>
    </div>
</fieldset>
<table id="demo" lay-filter="test"></table>
<!-- 引入jquery，需要联网才能使用 -->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/lib/layui-v2.6.3/layui.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn" lay-event="edit">编辑状态
        <span class="layui-badge" id="badge"></span>
    </a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
</script>

<script>
    layui.use(['table','util','form','layer','jquery'], function(){
        var table = layui.table;
        var util=layui.util;
        var form = layui.form;
        var $ = layui.jquery;
        var companyId=${company.companyId};
        var jobId = parent.jobId;
        console.log(jobId);
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 'full-50'
            ,url:'${pageContext.request.contextPath}/SelectResume?companyId='+companyId+"&jobId="+jobId
            ,method:'post'
            ,page: true //开启分页
            ,editTrigger: 'dblclick'//双击编辑
            ,id:'companyList'
            ,smartReloadModel:true
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'auditId', title: '审批号', width:150}
                ,{field: 'userName', title: '用户名', width:150, sort: true}
                ,{field: 'jobName', title: '职位名', width:150}
                ,{field: 'xueLi', title: '学历', width:150}
                ,{field: 'major', title: '专业', width:150}
                ,{field: 'salary', title: '薪资', width: 150}
                ,{field: 'jobType', title: '职位种类', width: 150}
                ,{field: 'addTime', title: '创建时间', width: 150, sort: true}
                ,{field: 'auditState', title: '状态', width: 150, sort: true, templet: '#state',}
                ,{field: 'src', title: '附件', width: 150, sort: true}
                ,{field: 'right', title: '操作', width: 300, toolbar:'#barDemo'} //toolbar 是工具栏
            ]]
            , done: function (res, curr, count) {//处理下拉框被隐藏和不能根据后台数据显示对应状态的问题

                //计数未读的简历
                // 获取数据并进行处理
                var data = res.data;
                // console.log(data[0].jobId);


                for(var i=0;i<res.data.length;i++){
                    var auditId=data[i].auditId;
                    $.ajax({
                        url: "${pageContext.request.contextPath}/addPointReadResume?auditId="+auditId+"&jobId="+jobId,
                        type: "GET",
                        async: false,//同步传输
                        dataType:"json",
                        success: function(data) {
                            // 更新未读消息数量
                            console.log(data);
                            if(data==0){
                                console.log("返回data！=0："+data);
                                // $("#ba.layui-badge").text(data);
                                var spanElem = $("tr[data-index="+ i +"] .layui-btn .layui-badge");
                                // var spanElem = $("#barDemo").eq(i).text();
                                console.log(spanElem);
                                spanElem.text("未查看");
                            }else{
                                console.log("返回data==0："+data);
                            }

                        }
                    });
                }


                count || this.elem.next('.layui-table-view').find('.layui-table-header').css('overflow', 'auto');
                layui.each($('.stateSelect'), function (index, item) {
                    var elem = $(item);
                    elem.val(elem.data('value')).parents('div.layui-table-cell').css('overflow', 'visible');
                });
                form.render();


            }

        });

        //监听行事件
        //触发单元格工具事件
        table.on('tool(test)', function(obj){ // 双击 toolDouble
            var data = obj.data;
            if(obj.event === 'edit'){
                //实现编辑功能
                //打开弹出层

                $.ajax({
                    url: "${pageContext.request.contextPath}/CheckedReadResume?auditId="+data.auditId+"&jobId="+jobId,
                    type: "GET",
                    async: false,//同步传输
                    dataType:"json",
                    success: function(data) {
                        // 更新未读消息数量
                        console.log(data);
                        if(data==1){
                            console.log("返回data！=0："+data);
                            // $("#ba.layui-badge").text(data);
                            var spanElem = $(this);
                            // var spanElem = $("#barDemo").eq(i).text();
                            console.log(spanElem);
                            spanElem.text();
                        }else{
                            console.log("返回data==0："+data);
                        }

                    }
                });


                layer.open({
                    type:2
                    ,title:'编辑企业信息'
                    ,content:'${pageContext.request.contextPath}/jsp/Company/resumeEditState.jsp'
                    //是否最大化
                    ,maxmin:true
                    ,area:['500px','450px']
                    ,btn:['确定','取消']
                    //回调函数
                    //参数 索引和layero
                    ,yes:function (index,layero) {
                        //回调的数值
                        var auditId=$(layero).find('iframe')[0].contentWindow.auditId.value;
                        var auditState=$(layero).find('iframe')[0].contentWindow.document.getElementById('auditState').value;
                        var opinion=$(layero).find('iframe')[0].contentWindow.document.getElementById('opinion').value;
                        console.log(auditId);
                        console.log(auditState);
                        console.log(opinion);


                        //同步数据表格中的数据
                        obj.update({
                            'auditState':auditState,
                            'auditId':auditId,
                            'opinion':opinion
                        })
                        $.ajax({
                            url:'${pageContext.request.contextPath}/EditResumeState?auditId='+auditId+"&auditState="+auditState+"&opinion="+opinion,
                            type:'post',
                            contentType:'application/json;charset=utf-8',
                            dataType:'text',
                            data:{
                                'auditState':auditState,
                                'auditId':auditId,
                                'opinion':opinion,
                            },
                            success:function(res){
                                if("success"==res){
                                    alert("恭喜你，编辑成功！")
                                }else {
                                    layer.msg("实在抱歉，编辑失败！");
                                }

                            },
                            error:function(res){
                                layer.msg("实在抱歉，编辑失败！");
                            }
                        })
                        layer.close(index);//关闭弹窗
                    },success:function (layero,index) {
                        var div = layero.find('iframe').contents().find('#useradmin');
                        var body = layer.getChildFrame('body',index);
                        var iframeWindow=window['layui-layer-iframe'+index];
                        //获取未修改前的默认数值到编辑框中，方便用户修改自己想修改的部分
                        body.find('#auditState').val(data.auditState);
                        body.find('#auditId').val(data.auditId);
                        body.find('#opinion').val(data.opinion);
                    }
                })

            }else if(obj.event === 'detail'){
                //打开弹出层
                layer.open({
                    type:2
                    ,title:'查看简历详情信息'
                    ,content:'${pageContext.request.contextPath}/jsp/Company/resumeDetail.jsp'
                    //是否最大化
                    ,maxmin:true
                    ,area:['500px','450px']
                    ,btn:['确定','取消']
                    //回调函数
                    //参数 索引和layero
                    ,yes:function (index,layero) {
                        //回调的数值
                        var auditId=$(layero).find('iframe')[0].contentWindow.auditId.value;
                        var description=$(layero).find('iframe')[0].contentWindow.document.getElementById('description').value;
                        console.log(auditId);
                        console.log(description);
                        //同步数据表格中的数据
                        obj.update({
                            'description':description,
                            'auditId':auditId,
                        })
                        layer.close(index);//关闭弹窗
                    },success:function (layero,index) {
                        var div = layero.find('iframe').contents().find('#useradmin');
                        var body = layer.getChildFrame('body',index);
                        var iframeWindow=window['layui-layer-iframe'+index];
                        //获取未修改前的默认数值到编辑框中，方便用户修改自己想修改的部分
                        body.find('#auditId').val(data.auditId);
                        body.find('#description').val(data.description);

                    }
                })
            }else if(obj.event === 'download'){
                console.log("download");
                window.location=data.src

            }

        });


    });

</script>
<script type="text/javascript">
    function select() {
        var keyCreateTime = $('#keyCreateTime').val();
        var keyState = $('#keyState').val();
        var keyEndTime = $('#keyEndTime').val();
        var companyId=${company.companyId};
        var jobId = parent.jobId;
        console.log(keyState);
        var table = layui.table;
        layui.table.reload('companyList', {
            page:{
                curr:1  //从第一页开始
            }
            ,page: true //开启分页
            ,method:'post'
            ,url:'${pageContext.request.contextPath}/SelectResume?companyId='+companyId+"&jobId="+jobId+"&keyCreateTime="+keyCreateTime+"&keyState="+keyState+"&keyEndTime="+keyEndTime,
            where:{
                keyCreateTime:keyCreateTime,
                keyState:keyState,
                keyEndTime:keyEndTime,
                companyId:companyId,
                jobId:jobId

            }
        });
    }

</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#keyCreateTime'
        });
        laydate.render({
            elem: '#keyEndTime'
            ,value: '2099-12-12'
            ,isInitValue: true
        });
    });
</script>


</body>
</html>